/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2024-11-08
 * Time: 19:11
 */
import java.util.*;

public class PrimeRing {
    private static final int[] PRIME_RING_SIZE = {5}; // 可以调整为其他值
    private static final int[] PRIME_NUMBERS = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}; // 小于30的所有素数

    private static boolean isPrime(int number) {
        for (int prime : PRIME_NUMBERS) {
            if (number % prime == 0 && number != prime) {
                return false;
            }
        }
        return true;
    }

    private static boolean checkQueue(Queue<Integer> queue) {
        if (queue.size() < 2) {
            return true;
        }
        int previous = queue.poll();
        boolean result = true;
        while (!queue.isEmpty()) {
            int current = queue.poll();
            if (!isPrime(current + previous)) {
                result = false;
                break;
            }
            previous = current;
        }
        queue.offer(previous);
        return result;
    }


    public static void solvePrimeRing(int n) {
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 2; i <= 2 * n; i++) {
            queue.offer(i);
        }


        while (!queue.isEmpty()) {
            if (checkQueue(queue)) {
                System.out.println(queue);
                return;
            }
            Queue<Integer> newQueue = new LinkedList<>(queue);
            int number = newQueue.poll();
            newQueue.offer(number);
            queue = newQueue;
        }
    }

    public static void main(String[] args) {
        solvePrimeRing(PRIME_RING_SIZE[0]);
    }
}
